package com.iemes.controller.quality;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.AcceptDeviationFormMap;
import com.iemes.mapper.quality.AcceptDeviationMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/quality")
@Controller
public class AcceptDeviationCoontroller extends BaseController {

	@Inject
	private AcceptDeviationMapper acceptDeviationMapper;
	
	@RequestMapping("acceptdeviation")
	private String fine(Model model){
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/quality/acceptdeviation/acceptdeviation_list";
	}
	
	@ResponseBody
	@RequestMapping("acceptdeviation_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception 
	{
		AcceptDeviationFormMap acceptDeviationFormMap=getFormMap(AcceptDeviationFormMap.class);
		List<Map<String,Object>> acceptDeviationFormMaps=acceptDeviationMapper.getAcceptDeviationByCondition(acceptDeviationFormMap);
		
		for(Map<String,Object>map:acceptDeviationFormMaps){
			if(map.get("classification").toString().equals("1")){
				map.put("classification", "原材料");
			}
			if(map.get("classification").toString().equals("2")){
				map.put("classification", "成品");
			}
			if(map.get("classification").toString().equals("3")){
				map.put("classification", "半成品");
			}
		}
		
		LuogicPaging(pageNow, pageSize, acceptDeviationFormMaps);
		return pageView;
	}
	
	
	@ResponseBody
	@RequestMapping(value="acceptdeviation_deleteEntity")
	@SystemLog(module="特采",methods="特采-删除")//凡需要处理业务逻辑的.都需要记录操作日志
	public String deleteEntity() throws Exception {
		AcceptDeviationFormMap acceptDeviationFormMap=getFormMap(AcceptDeviationFormMap.class);
		String[] ids = getParaValues("ids");
		String arr=ids[0];
		String[] str=arr.split(",");
		for(int i=0;i<str.length;i++){
			acceptDeviationFormMap.put("state", 1);
			acceptDeviationFormMap.put("id", str[i]);
			baseMapper.editEntity(acceptDeviationFormMap);
		}
		return "success";
	}
		
	@RequestMapping("acceptdeviation_addUI")
	public String addUI(Model model) throws Exception {
		return Common.BACKGROUND_PATH + "/quality/acceptdeviation/acceptdeviation_add";
	}
	
	

	@ResponseBody
	@RequestMapping("acceptdeviation_addEntity")
//	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module="特采",methods="特采-新增物料")//凡需要处理业务逻辑的.都需要记录操作日志
	public String addEntity() throws Exception {
		AcceptDeviationFormMap acceptDeviationFormMap=getFormMap(AcceptDeviationFormMap.class);
		acceptDeviationFormMap.put("state", 0);
		System.out.println("我看一下H5的时间格式先"+acceptDeviationFormMap.getStr("applyDate"));
		acceptDeviationMapper.addEntity(acceptDeviationFormMap);
		return "success";
	}
	
	
	@RequestMapping("acceptdeviation_edit")
	public String editUI(Model model) throws Exception 
	{
		String id = getPara("id");
		AcceptDeviationFormMap acceptDeviationFormMap=acceptDeviationMapper.getAcceptDeviationFormMapById(Integer.parseInt(id));
		model.addAttribute("acceptDeviationFormMap", acceptDeviationFormMap);
		return Common.BACKGROUND_PATH + "/quality/acceptdeviation/acceptdeviation_edit";
	}
	
	
	@ResponseBody
	@RequestMapping(value="acceptdeviation_editEntity")
	@SystemLog(module="特采",methods="特采-修改")//凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity() throws Exception {
		AcceptDeviationFormMap acceptDeviationFormMap=getFormMap(AcceptDeviationFormMap.class);
		acceptDeviationMapper.editEntity(acceptDeviationFormMap);
		return "success";
	}
	
}
